package com.hou.listener;

import org.springframework.cloud.netflix.eureka.server.event.*;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * 监听服务,监听不同event即可
 */
@Component
public class ServiceStatusListener {
    //服务下线
    @EventListener
    public void listener(EurekaInstanceCanceledEvent event){
        System.out.println("服务下线:"+event.getServerId()+","+event.getAppName());
    }
    //服务注册
    @EventListener
    public void listener(EurekaInstanceRegisteredEvent event){
        System.out.println("服务正在注册:"+event.getInstanceInfo().getAppName());
    }
    //eureka启动监听
    @EventListener
    public void listener(EurekaRegistryAvailableEvent event){
        System.out.println("注册中心启动:"+event.getSource());
    }
    //服务续约,心跳监听
    @EventListener
    public void listener(EurekaInstanceRenewedEvent event){
        System.out.println("服务心跳:"+event.getServerId()+","+event.getAppName());
    }
    //eureka server 启动监听
    @EventListener
    public void listener(EurekaServerStartedEvent event){
        System.out.println("eureka server启动:"+event.getSource());
    }
}
